'use strict';
exports.main = async (event, context) => {
	const {phone} = event
	
	//创建随机验证码
	const currentNumber = Math.random().toString().substr(2,6)
	
	 try {
	    const res = await uniCloud.sendSms({
	      appid: '__UNI__E5FD13A',
	      smsKey: '8a27964d6dd2c90f29fab1d0602e6b29',
	      smsSecret: 'b1f43488612542eec052a8433aa989e4',
	      phone,
	      templateId: '100**', // 请替换为自己申请的模板id,短信模板id
	      data: {
	        code: currentNumber,
	        expMinute: '1',
	      }
	    })
	    // 调用成功，请注意这时不代表发送成功
	    return {
			code:0,
			data:{
				msg:"请注意在手机查收验证码",
				mobileCode:currentNumber
			}
		}
	  } catch(err) {
	    // 调用失败
	    return {
	      code: 1,
	      msg: "短信验证码获取失败"
	    }
	  }
};
